/*
 * @Descripttion: 
 * @version: 请写项目版本
 * @Author: @cdm
 * @Date: 2021-12-20 13:48:32
 * @LastEditors: @cdm
 * @LastEditTime: 2021-12-20 13:49:39
 * No pains no gains
 */
/**
 * 触摸事件扩展类
 * Created by 4399 on 21-02-07.
 */

 import { lib } from "./components/TouchCpt";

 export class TouchExtend {
     // 清除节点上原先添加的监听事件
     static clearTouchEvents (node:cc.Node) {
         let touchCpt = node.getComponent(lib.TouchCpt);
         if(touchCpt) {
             touchCpt.clearTouchEvents();
         }
     }
 
     static touchEvent(node: cc.Node, event:string, func?:Function, target?:object) {
         let touchCpt = this._addTouchCpt(node);
         //touchCpt.isTouches = true;
         touchCpt.setTouchEvent(event, func, target);
         return touchCpt;
     }
 
     static _addTouchCpt(node:cc.Node) {
         let touchCpt = node.getComponent(lib.TouchCpt);
         if(!touchCpt) {
             touchCpt = node.addComponent(lib.TouchCpt);
         }
         return touchCpt;
     }
 
     static touchEvents (node:cc.Node, endFunc?:Function, target?:object, beginFunc?:Function, moveFunc?:Function, cancelFunc?:Function, isOneClick:boolean = true, isStopPropagation:boolean = true) {
         let touchCpt = this._addTouchCpt(node);
         //touchCpt.isTouches = true;
         touchCpt.isTouchOneByOne = isOneClick;
         touchCpt.isStopPropagation = isStopPropagation;
         touchCpt.isScaleEffect = false;
         touchCpt.setTouchEvents(endFunc, beginFunc, moveFunc, cancelFunc, target);
         return touchCpt;
     }
 
     static touchEndScale(node:cc.Node, endFunc:Function, soundName:string = 'big_btn_click', target?:object) {
         return this.touchEventsScale(node, endFunc, target, null, null, null, true, soundName);
     }
 
     static touchEventsScale (node:cc.Node, endFunc?:Function, target?:object, beginFunc?:Function, moveFunc?:Function, cancelFunc?:Function, isOneClick:boolean = true, soundName:string = 'big_btn_click', notCenter?:boolean) {
         if(!node) {
             return ;
         }
         let touchCpt = this._addTouchCpt(node);
         //touchCpt.isTouches = true;
         touchCpt.isTouchOneByOne = isOneClick;
         touchCpt.soundName = soundName;
         touchCpt.setTouchEvents(endFunc, beginFunc, moveFunc, cancelFunc, target);
         return touchCpt;
     }
 
     static touchEndScaleNotCenter(node:cc.Node, endFunc?:Function, target?:object) {
         this.touchEventsScale(node, endFunc, target, null, null, null, null, null, true);
     }
 
     // // 持续点击事件  duration间隔时间
     static lastTouchEndEventScale(node:cc.Node, func:Function, duration:number = 0.3, target?:object, endFunc?:Function, isOneClick:boolean = true) {
         let touchCpt = this._addTouchCpt(node);
         touchCpt.isTouchOneByOne = isOneClick;
         touchCpt.setLastTouchEvent(func, duration, target, endFunc || func);
     }
 
     static addExtraTouchEvent(node:cc.Node, func:Function, once:boolean = true, target?:object) {
         if(!node) {
             return ;
         }
         this._addTouchCpt(node).addExtraTouchEvent(func, once, target);
     }
 
     // 双击
     static doubleClickScale(node:cc.Node, doubleClick:Function, endFunc:Function, target?:object, duration:number = 0.2, isOneClick:boolean = true) {
         let touchCpt = this._addTouchCpt(node);
         touchCpt.isTouchOneByOne = isOneClick;
         touchCpt.setDoubleClickEvent(doubleClick, endFunc, target, duration);
     }
 }